/*
 * INSANE - Interactive Structural Analysis Environment
 *
 * Copyright (C) 2003-2006
 * Universidade Federal de Minas Gerais
 * Escola de Engenharia
 * Departamento de Engenharia de Estruturas
 *
 * Author's email :     insane@dees.ufmg.br
 * Author's Website :   http://www.dees.ufmg.br/insane
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 */
 
package br.ufmg.dees.insane.draw;

import java.awt.Dimension;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.geom.Arc2D;
import java.awt.geom.Line2D;
import java.util.Vector;

/**
 * @author Fonseca, Flavio & Pitangueira, Roque
 * @since February 2004
 */
public abstract class ArrowDraw extends Draw {
    
    private double value = 0;
	private double position = 0;
    
//*****************************************************************************
	
    public void setValue(double value) {
        this.value = value;
    }
    
//*****************************************************************************
	
    public double getValue() {
        return value;
    }
	
//*****************************************************************************
	
	public void setPosition(double position) {
		this.position = position;
	}
	
//*****************************************************************************
	
	public double getPosition() {
		return this.position;
	}
    
//*****************************************************************************
	
    public static class Out extends ArrowDraw {
        public Out() {
            this(new Point(0, 0));
        }
        
        public Out(Point loc) {
            this(loc, 0);
        }
        
        public Out(Point loc, double theta) {
            this(loc, theta, 0);
        }
        
        public Out(Point loc, double theta, double value) {
            this(loc, theta, value, null);
        }
        
        public Out(Point loc, double theta, double value, Object represents) {
            this.setLocation(loc);
            this.setAngle(theta);
            this.setValue(value);
            this.setRepresents(represents);
            this.setSize(new Dimension(18, 4));
        }
        
        public boolean equals(Object obj) {
            if (super.equals(obj) && obj instanceof ArrowDraw.Out) {
                ArrowDraw.Out d = (ArrowDraw.Out)obj;
                if (d.getValue() == getValue()){
                    return true;
                }
            }
            return false;
        }
		
        public Vector<Object> getShapes() {
            
            Vector<Object> shapes = new Vector<Object>();
            
            int x = this.getLocation().x;
            int y = this.getLocation().y;
            int width = this.getSize().width;
            double scale = this.getScale();
            
            double MOD = width * scale * Math.abs(this.getValue()) / 10;
			
            double ARROW = 6;
			if (MOD < ARROW) {
				ARROW = MOD;
			}
            
            if (this.getValue() > 0) {
				x = x - 5;
				shapes.add(new Line2D.Double(x, y, x-ARROW, y+(ARROW/2)));
                shapes.add(new Line2D.Double(x, y, x-ARROW, y-(ARROW/2)));
                shapes.add(new Line2D.Double(x-MOD, y, x, y));
            } else if (this.getValue() < 0) {
                x = x + 5;
				shapes.add(new Line2D.Double(x, y, x+ARROW, y+(ARROW/2)));
				shapes.add(new Line2D.Double(x, y, x+ARROW, y-(ARROW/2)));
				shapes.add(new Line2D.Double(x, y, x+MOD, y ));
            }
            
            return shapes;
        }
        
        /**
         * Returns the draw bounds in device units.
         *
         * @return the draw bounds
         */
        public Rectangle getBounds() {
            
            int x = this.getLocation().x;
            int y = this.getLocation().y;
            int width = this.getSize().width;
            double scale = this.getScale();
            
            int W = (int)(width * scale * Math.abs(this.getValue()));
            int H = (int)(W/7);
            return new Rectangle(x, (int)(y - H/2), W, H);
        }
        
    }
    
//*****************************************************************************
	
    public static class AntiClockwise extends ArrowDraw {
        public AntiClockwise() {
            this(new Point(0, 0));
        }
        
        public AntiClockwise(Point loc) {
            this(loc, 0);
        }
        
        public AntiClockwise(Point loc, double theta) {
            this(loc, theta, 0);
        }
        
        public AntiClockwise(Point loc, double theta, double value) {
            this(loc, theta, value, null);
        }
        
        public AntiClockwise(Point loc, double theta, double value, Object represents) {
            this.setLocation(loc);
            this.setAngle(theta);
            this.setValue(value);
            this.setRepresents(represents);
            this.setSize(new Dimension(8, 8));
        }
		
        public boolean equals(Object obj) {
            if (super.equals(obj) && obj instanceof ArrowDraw.AntiClockwise) {
                ArrowDraw.AntiClockwise d = (ArrowDraw.AntiClockwise)obj;
                if (d.getValue() == getValue()){
                    return true;
                }
            }
            return false;
        }
		
        public Vector<Object> getShapes() {
            
            Vector<Object> shapes = new Vector<Object> ();
            
            int x = this.getLocation().x;
            int y = this.getLocation().y;
            int width = this.getSize().width;
            int height = this.getSize().height;
            double scale = this.getScale();
			
            double W = width * 4;
            double H = height * 4;
            
            if (this.getValue() > 0 && scale!=0) {
                shapes.add( new Arc2D.Double(x - W/2, y - H/2, W, H, -75, 225, 0));
                shapes.add( new Line2D.Double(x - 0.433 * W, y - H/4, x - 0.43 * W, y - 0.5 * H));
                shapes.add( new Line2D.Double(x - 0.433 * W, y - H/4, x - 0.25 * W, y - 0.28 * H));
            }else if (this.getValue() < 0 && scale!=0) {
                shapes.add( new Arc2D.Double( x - W/2, y - H/2, W, H, -75, 225, 0));
                shapes.add( new Line2D.Double( x + W/8, y + H/2, x + 0.2 * W, y + 0.3 * H));
                shapes.add( new Line2D.Double( x + W/8, y + H/2, x + 0.325 * W, y + 0.5 * H));
            }
            
            return shapes;
        }
        
        /**
         * Returns the draw bounds in device units.
         *
         * @return the draw bounds
         */
        public Rectangle getBounds() {
            
            int x = this.getLocation().x;
            int y = this.getLocation().y;
            int W = this.getSize().width * 4;
            int H = this.getSize().height * 4;
            
            return new Rectangle((int)(x - W/2), (int)(y - H/2), W, H);
        }
        
    }
    
//*****************************************************************************
}
